package com.tan00xu.controller;

import com.tan00xu.service.CategoryService;
import com.tan00xu.utils.CmdOutputInformationUtils;
import com.tan00xu.vo.CategoryVo;
import com.tan00xu.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取文章的所有分类
     * @return Result 分类数据
     */
    @GetMapping("/listAllCategories")
    public Result listCategories() {
        CmdOutputInformationUtils.info("CategoryController下的listAllCategories被请求了=>获取文章的所有分类");
        return categoryService.listAllCategories();
    }

    /**
     * 获取所有分类的详细信息
     * @return
     */
    @GetMapping("/listAllCategoriesDetail")
    public Result listAllCategoriesDetail() {
        CmdOutputInformationUtils.info("CategoryController下的listAllCategoriesDetail被请求了=>获取所有分类的详细信息");
        return categoryService.listAllCategoriesDetail();
    }

    /**
     * 根据分类id获取分类详情
     * @return
     */
    @GetMapping("/getCategoryDetailByCategoryId/{categoryId}")
    public Result getCategoryDetailByCategoryId(@PathVariable("categoryId") Long categoryId) {
        CmdOutputInformationUtils.info("CategoryController下的listArticleByCategoryId被请求了=>获取当前分类下的文章列表");
        CategoryVo categoryVo = categoryService.getCategoryById(categoryId);
        return Result.success("获取该分类的详细信息成功", categoryVo);
    }


}
